package com.semis.web.controller.base;

import java.util.List;
import java.util.Arrays;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.semis.common.annotation.Log;
import com.semis.common.core.controller.BaseController;
import com.semis.common.core.domain.AjaxResult;
import com.semis.common.enums.BusinessType;
import com.semis.business.system.domain.SysFiles;
import com.semis.business.system.service.ISysFilesService;
import com.semis.common.utils.poi.ExcelUtil;
import com.semis.common.core.page.TableDataInfo;

/**
 * 系统附件Controller
 *
 * @author cyxh
 * @date 2024-06-11
 */
@Api(tags="系统附件管理")
@RestController
@RequestMapping("/system/files")
public class SystemFilesController extends BaseController
{
    @Autowired
    private ISysFilesService sysFilesService;

    /**
     * 查询系统附件列表
     */
    @ApiOperation("查询系统附件列表")
    //@PreAuthorize("@ss.hasPermi('system:files:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysFiles sysFiles)
    {
        startPage();
        List<SysFiles> list = sysFilesService.selectSysFilesList(sysFiles);
        return getDataTable(list);
    }

    /**
     * 导出系统附件列表
     */
    @ApiOperation("导出系统附件列表")
    //@PreAuthorize("@ss.hasPermi('system:files:export')")
    @Log(title = "系统附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysFiles sysFiles)
    {
        List<SysFiles> list = sysFilesService.selectSysFilesList(sysFiles);
        ExcelUtil<SysFiles> util = new ExcelUtil<SysFiles>(SysFiles.class);
        util.exportExcel(response, list, "系统附件数据");
    }

    /**
     * 获取系统附件详细信息
     */
    @ApiOperation("获取系统附件详细信息")
    //@PreAuthorize("@ss.hasPermi('system:files:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(sysFilesService.getById(id));
    }

    /**
     * 新增系统附件
     */
    @ApiOperation("新增系统附件")
    //@PreAuthorize("@ss.hasPermi('system:files:add')")
    @Log(title = "系统附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysFiles sysFiles)
    {
        return toAjax(sysFilesService.save(sysFiles));
    }

    /**
     * 修改系统附件
     */
    @ApiOperation("修改系统附件")
    //@PreAuthorize("@ss.hasPermi('system:files:edit')")
    @Log(title = "系统附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysFiles sysFiles)
    {
        return toAjax(sysFilesService.updateById(sysFiles));
    }

    /**
     * 删除系统附件
     */
    @ApiOperation("删除系统附件")
    //@PreAuthorize("@ss.hasPermi('system:files:remove')")
    @Log(title = "系统附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(sysFilesService.removeByIds(Arrays.asList(ids)));
    }
}
